package com.jade.explorer.dirscan;

import java.io.File;

import org.eclipse.core.runtime.IAdaptable;

public class TreeObject implements IAdaptable{
	
	//------------------------------Private fields
	private String _name;
	private String _path;
	private TreeParent _parent;
	private FileType _type;
	private String _ext = null;
	
	
	//------------------------------Private methods
	private void type_scan(){
		String extb = "";
		for (int i = _path.length()-1; i >=0; i--){
			if (_path.charAt(i) == '.') break;
			extb += _path.charAt(i);
		}
		
		String ext = "";
		for(int i = extb.length()-1; i >=0; i--){
			ext += extb.charAt(i);
		}
		
		ext.toLowerCase();
		
		switch (ext){
			case "project"	: _type = FileType.HIDDEN; break;
			case "jade"		: _type = FileType.OBJECT; break;
			case "ani"		: _type = FileType.ANISOTROPY; break;
			case "jpeg"		:
			case "png"		:
			case "bmp"		:
			case "jpg"		: _type = FileType.IMAGE; break;
			case "domain"		: _type = FileType.DOMAIN; break;
			default			: _type = FileType.UNKNOWN;
			
		}
		
		_ext = "." + ext;
	}
	
	
	//------------------------------Constructors
	public TreeObject(String name, String path) {
		this._name = name;
		this._path = path;
		type_scan();
	}
	
	public TreeObject(String name, String path, FileType type){
		this._name = name;
		this._path = path;
		this._type = type;
	}
	
	//------------------------------Public methods
	public void setType(FileType ft){
		_type = ft;
	}
	
	
	public FileType getType(){
		return _type;
	}
	
	
	public String getExtension(){
		return _ext;
	}
	
	
	public void setPath(String path){
		this._path = path;
	}
	
	
	public String getPath(){
		return _path;
	}
	
	
	public String getName() {
		if (new File(_path).exists() && new File(_path).isFile()){
			String name = "";
			for (int i = 0; i < _name.lastIndexOf('.'); i++){
				name += _name.charAt(i);
			}
			return name;
		}
		return _name;
	}
	
	private String remExt(){
		String tmp = "";
		String name = "";
		
		
		
		return name;
	}
	
	
	public String getFullName(){
		return _name;
	}
	
	
	public void setParent(TreeParent parent) {
		this._parent = parent;
	}
	
	
	public String toString() {
		return getName();
	}
	
	
	@SuppressWarnings("rawtypes")
	public Object getAdapter(Class key) {
		return null;
	}
	
	public TreeParent getParent() {
		return _parent;
	}

}
